package cn.itcast.web.controller.cargo;

import cn.itcast.domain.cargo.Packing;
import cn.itcast.domain.cargo.Shipping;
import cn.itcast.domain.cargo.ShippingExample;
import cn.itcast.service.cargo.ShippingService;
import cn.itcast.web.controller.BaseController;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/cargo/map")
public class ShippingMapController extends BaseController{

    @Reference
    private ShippingService shippingService;

/*    @RequestMapping("/shippingMap")
    public String shippingMap(String id){
        //1.根据货物id查询
        Shipping shipping = shippingService.findById(id);
        //2.判断收发地港口并显示

        request.setAttribute("map",shipping);
        //转发到地图
        return "/cargo/map/shipping-map";
    }*/
    //跳转到 地图
    @RequestMapping("/shippingMap")
    public String shippingMap(String id){
        //1.根据货物id查询
        Shipping shipping = shippingService.findById(id);

        //2.判断收发地港口并显示
        request.setAttribute("shippingId",shipping);

        //转发到地图
        return "/cargo/map/shipping-map2";
    }

    //根据填写的地址进行修改 发货地 转货港 卸货港
    @RequestMapping("/update")
    public String update(String id,String portOfLoading,String portOfTrans,String portOfDischarge){
        //根据id查询
       Shipping shipping = shippingService.findById(id);
       shipping.setPortOfLoading(portOfLoading);  //发货地
       shipping.setPortOfTrans(portOfTrans);  //转货港
       shipping.setPortOfDischarge(portOfDischarge); //卸货港
        //更新
       shippingService.update(shipping);
       request.setAttribute("shipping",shipping.getId());

        Shipping show = shippingService.findById(id);
        request.setAttribute("shippingId",show);
        return "/cargo/map/shipping-map2";
    }

}
